/** @file  get_name.c
 *  @brief  check the string
 * 
 *  Functiont to Check the string is valid or not 
 *   
 *  @author Karthik M 
 *  @bug No  bugs.
 */


#include "header.h"


char * get_name (char *line)
{

   char *ptr ;										//! ptr to skip spaces 
   char *temp;
   int flag  = 0;									//! flag to check string or not 
   int count= 0;


get_line :

   if (( fgets (line, LINEMAX,stdin) )== NULL) {
      fprintf (stderr," error in reading  string \n");
      exit(2);
   }


   line[strlen(line)-1] = '\0';				//! making  the buffer end to NULL 
   //! skiping the white spaces 
   for ( ptr = line ;*ptr == ' ' || *ptr == '\t' ; ptr++ )
      ;

   temp = ptr ;
   while (*ptr){

      if (*ptr <= 32 || *ptr == 127 )			//! check for the character 
      {
         flag =1 ;
         printf (" flag is set \n");
      }
      ptr++;
      count++;
   }


   if (flag == 1 || count >=NAMEMAX ){
      flag = 0;								//! do untill valid input received 
      count = 0;
      printf (" enter the valid string \n");
      goto get_line ;
   }
   else
      return temp ;									//! return valid string address 

}
